﻿Public Class registroBO


    Dim registro As New registroDAO

    Public Function getRegistro(ByVal NUM_REGISTRO As Integer, ByVal ano As Integer) As registroVO
        Try
            Return registro.getRegistro(NUM_REGISTRO, ano)
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function getRegistro(ByVal NUM_REGISTRO As Integer, ByVal ano As Integer, ByVal id_natureza As Integer) As registroVO
        Try
            Return registro.getRegistro(NUM_REGISTRO, ano, id_natureza)
        Catch ex As Exception
            Throw ex
        End Try
    End Function


    Public Function getRegistroSimplificado(ByVal NUM_REGISTRO As Integer, ByVal ano As Integer, Optional ByVal id_natureza As Integer = Nothing) As registroVO
        Try
            Return registro.getRegistroSimplificado(NUM_REGISTRO, ano, id_natureza)
        Catch ex As Exception
            Throw ex
        End Try
    End Function


    Public Function getUltimoRegistro() As Integer
        Try
            Return registro.getUltimoRegistro()
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Function insereRegistro(ByVal regInserido As registroVO, Optional ByVal ehLaudoGeral As Boolean = False) As Integer
        Try
            Return registro.insereRegistro(regInserido, ehLaudoGeral)
        Catch ex As Exception
            Throw ex
        End Try

    End Function
    Public Function updateRegistro(ByVal regInserido As registroVO, _
                                   Optional ByVal provas As String = Nothing, Optional ByVal id_usuario As Integer = 0, _
                                   Optional ByVal nomeDiretorio As String = Nothing, _
                                   Optional ByVal uc As ucPreambulo = Nothing) As Integer
        Try
            Return registro.updateRegistro(regInserido, provas, id_usuario, nomeDiretorio, uc)
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function deleteRegistro(ByVal regInserido As registroVO, _
                                   Optional ByVal ehNovo As Boolean = False, _
                                   Optional ByVal uc As ucPreambulo = Nothing, _
                                   Optional ByVal erro As Integer = 0, _
                                   Optional ByVal nomeDiretorio As String = Nothing, _
                                   Optional ByVal armaRelatorio As armaRelatorioVO = Nothing, _
                                    Optional ByVal drogaRelatorio As List(Of drogaRelatorioVO) = Nothing) As Boolean
        Dim apagouDados As Boolean = False
        Try
            '-------------------------------------------------------
            ' SE O REGISTRO INSERIDO FOR UM NOVO
            '------------------------------------------------------
            registro.deleteRegistro(regInserido, ehNovo, uc, erro, armaRelatorio, drogaRelatorio)

            If erro = 2 Then
                If Not IsNothing(regInserido.NOME_DIRETORIO) Then

                    generica.deletaDiretorio(regInserido.NOME_DIRETORIO)
                Else
                    generica.deletaDiretorio(nomeDiretorio)
                End If
            End If
            apagouDados = True
        Catch ex As Exception
            Throw ex
        End Try
        Return apagouDados
    End Function

    'Shared Function rollBack(ByVal registro As registroVO, _
    '                     ByVal nomeDiretorio As String, _
    '                     ByVal erro As Integer, _
    '                     Optional ByVal ehNovo As Boolean = Nothing, _
    '                     Optional ByVal uc As ucPreambulo = Nothing)


    '    Dim apagouDados As Boolean = False
    '    Try
    '        registro.deleteRegistroPontuacao(regInserido)
    '        generica.deletaDiretorio(regInserido.NOME_DIRETORIO)
    '        apagouDados = True
    '    Catch ex As Exception
    '        Throw ex
    '    End Try
    '    Return apagouDados
    'End Function

    Public Function getRegistros(ByVal txtBusca As String) As DataTable
        Try
            Return registro.getRegistros(txtBusca)
        Catch ex As Exception
            Throw ex
        End Try
    End Function


    Public Function getLaudosSecao(ByVal id_secao As Integer, Optional ByVal vitima As String = Nothing) As DataTable
        Try

            Return registro.getLaudosSecao(id_secao, vitima)

        Catch ex As Exception

            Throw ex

        End Try


    End Function

    Public Function getRegistrosComAtraso(ByVal id_usuario As Integer, Optional ByVal txtBusca As String = Nothing) As DataTable
        Try

            Return registro.getRegistrosComAtraso(id_usuario, txtBusca)

        Catch ex As Exception

            Throw ex

        End Try


    End Function


End Class
